#include "TimeFramework.h"

int TimeFramework::init()
{
	m_frequency = 0;
	m_start = 0;
	m_ticks = 0;
	m_time = 0;
	m_previous = 0;
	m_elapsed = 0;

	QueryPerformanceFrequency((LARGE_INTEGER*)&m_frequency);
	if(m_frequency == 0) return TIM_INIT_HFQ_SUPPORT_ERROR;
	m_ticks = (float)(m_frequency/1000);
	QueryPerformanceCounter((LARGE_INTEGER*)&m_start);

	return TIM_SUCCESS;
}

int TimeFramework::update()
{
	INT64 current;
	float difference;

	QueryPerformanceCounter((LARGE_INTEGER*)&current);
	difference = (float)(current/1000);
	m_time = difference/m_ticks;
	m_start = current;
	if(m_previous != 0.0f)
		m_elapsed = m_time-m_previous;
	else 
		m_elapsed = 0.0f;
	m_previous = m_time;

	return TIM_SUCCESS;
}